package org.example.service.impl;

import org.example.dao.UserDao;
import org.example.entity.User;
import org.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author CoderXshuai
 * @date 2020/9/4/0004 14:58
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;

    @Override
    public void insertUser(User user) {
        userDao.save(user);
    }

    @Override
    public void deleteUser(Integer uid) {
        userDao.deleteById(uid);
    }

    @Override
    public void updateUser(User user) {
        userDao.save(user);
    }

    @Override
    public List<User> findAllUser() {
        Iterable<User> userIterable = userDao.findAll();
        List<User> userList = new ArrayList<>();
        userIterable.forEach(userList::add);
        return userList;
    }

    @Override
    public User login(String username, String psw) {
        return userDao.findByUsernameAndPsw(username, psw);
    }
}
